import 'package:dio/dio.dart';

// ignore: non_constant_identifier_names
Future FutureDio(String methods, String api, Map<String, dynamic> obj,{FormData formData}) async {
  print(api);
  print(obj);
  /// 自定义Header
  Map<String, dynamic> httpHeaders = {
    'Accept': 'application/json,*/*',
    'Content-Type': 'application/json'
  };

  var options = BaseOptions(
      sendTimeout:120000,
      connectTimeout: 120000,
      receiveTimeout: 120000,
      responseType: ResponseType.json,
      validateStatus: (status) {
        // 不使用http状态码判断状态，使用AdapterInterceptor来处理（适用于标准REST风格）
        return true;
      },
      headers: httpHeaders);

  Dio dio = new Dio(options);

  Response response;
  /// 判断请求的方式调用dio不同的请求api
  if (methods == "post") {
    response = await dio.post(api, data: obj);
  } else if (methods == 'get') {
    response = await dio.get(api, queryParameters: obj);
  } //注意get请求使用queryParameters接收参数，post请求使用data接收参数
  ///返回正常
  else if(methods == "upload"){
    response = await dio.post(api, data:formData,queryParameters: obj,options: Options(
      contentType: "multipart/form-data"
    ));
  }
  return response; //返回请求结果
}
